class Solution {
public:
    bool check(vector<int>arr,int x)
    {
        int left=0;
        int right=arr.size()-1;
        while(left<right)
        {
            int mid=left+((right-left)>>1);
            if(arr[mid]<x)left=mid+1;
            else if(arr[mid]>=x)right=mid;
        }
        return arr[right]==x;
    }
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int n=matrix.size();
        bool flag=false;
        for(int i=0;i<n;i++)
        {
            flag=check(matrix[i],target);
            if(flag)return true;
        }
        return false;
    }
};
